package com.vict.util;

import java.util.ArrayList;
import java.util.List;

public class ListUtil {
    /**
     *
     * @param list 数组
     * @param size 切分大小
     * @param <T> 类型
     * @return
     */
    public static <T> List<List<T>> groupByNum(List<T> list, int size){
        if(list == null){
            return null;
        }
        ArrayList<List<T>> lists = new ArrayList<>();
        if(list.size() == 0){
            lists.add(list);
            return lists;
        }
        if(size <= 0){
            lists.add(list);
            return lists;
        }
        for(int i = 0 ; i < list.size() ; i += size){
            List<T> subList = list.subList(i, i + size > list.size() ? list.size() : i + size);
            lists.add(subList);
        }
        return lists;
    }
}
